package com.archermind.empsys.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.archermind.empsys.utils.JdbcUtils;

public class TransactionFilter implements Filter {
	
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		
		//获取开启事务的链接，并把连接绑定到当前线程󶨵���ǰ�߳�
		try{
			chain.doFilter(request, response);   //dao1:JdbcUtils.getConnection()  dao2:JdbcUtils.getConnection()
			JdbcUtils.commit();
		}catch (Exception e) {
			JdbcUtils.rollback();
			throw new RuntimeException(e);
		}finally{
			JdbcUtils.closeConn();
		}
	}

	

	public void destroy() {
		// TODO Auto-generated method stub

	}

	
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub

	}

}
